package validator;

import model.Enterprise;
import model.Person;
import model.type.EmployeeRoleType;
import db.ImbiConnection;

public class EmployeeRoleValidator {
	private Integer person, enterprise;
	private EmployeeRoleType role;
	
	public EmployeeRoleValidator(String person, String enterprise, String role){
		try{
			this.person = Integer.parseInt(person);
		} catch(NullPointerException | NumberFormatException e){ }
		try{
			this.enterprise = Integer.parseInt(enterprise);
		} catch(NullPointerException | NumberFormatException e){ }
		try{
			this.role = EmployeeRoleType.getEmployeeRoleType(Integer.parseInt(role));
		} catch(NullPointerException | NumberFormatException e){ }		
	}
	
	public boolean isValid(){
		return person != null && enterprise != null && role != null;
	}

	public Integer getPerson() {
		return person;
	}

	public Integer getEnterprise() {
		return enterprise;
	}

	public EmployeeRoleType getRole() {
		return role;
	}	
	
	public boolean isLogicallyValid(){
		if(!isValid()) return false;
		Person p = ImbiConnection.getPersonDAO().find(person);
		Enterprise e = ImbiConnection.getEnterpriseDAO().find(enterprise);
		return p != null && e != null;		
	}
}
